/* hash - hashing table processing.
   Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
   Written by Jim Meyering <meyering@ascend.com>, 1998.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

/* A generic hash table package.  */

/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
   obstacks instead of malloc, and recompile `hash.c' with same setting.  */

#ifndef HASH_H_
#define HASH_H_

typedef unsigned (*pfunc_HashHasher) (const void *, unsigned);
typedef bool (*pfunc_HashComparator) (const void *, const void *);
typedef void (*pfunc_HashDataFreer) (void *);

struct hash_table;
// This structure is mainly used for `hash_initialize', see the block 
// documentation of `hash_reset_tuning' for more complete comments.
struct hash_tuning
{
  float shrink_threshold;	// ratio of used buckets to trigger a shrink
  float shrink_factor;  	// ratio of new smaller size to original size
  float growth_threshold;	// ratio of used buckets to trigger a growth
  float growth_factor;	  // ratio of new bigger size to original size
  bool is_n_buckets;		  // if CANDIDATE really means table size
};

typedef struct hash_tuning Hash_tuning;
typedef struct hash_table Hash_table;

// Information and lookup.
void *hash_lookup (const Hash_table *, const void *);

// Allocation and clean-up.
Hash_table *hash_initialize (unsigned, const Hash_tuning *,
				     pfunc_HashHasher, 
             pfunc_HashComparator,
				     pfunc_HashDataFreer);

// Insertion and deletion.
void *hash_insert (Hash_table *, const void *);

#endif // HASH_H_
